package com.jinzhi;

import com.jinzhi.common.config.IFastConfig;
import com.jinzhi.common.utils.SpringContextHolder;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.annotation.ImportResource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@Slf4j
@EnableTransactionManagement
@ServletComponentScan
@MapperScan("com.jinzhi.**.dao")
@SpringBootApplication
@EnableScheduling
@ImportResource({"classpath*:link/applicationContext*.xml"})
//开启异步调用方法
@EnableAsync
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
        printProjectConfigs();
    }

    private static void printProjectConfigs() {
        ServerProperties serverProperties = SpringContextHolder.getApplicationContext().getBean(ServerProperties.class);
        DataSourceProperties dataSourceProperties = SpringContextHolder.getApplicationContext().getBean(DataSourceProperties.class);
        IFastConfig config = SpringContextHolder.getApplicationContext().getBean(IFastConfig.class);
        log.info("开启演示模式：{}", config.isDemoMode());
        log.info("开启调试模式：{}", config.isDevMode());
        log.info("数据库：{}", dataSourceProperties.getUrl());
        log.info("==================> run at http://localhost:{}  <==================", serverProperties.getPort() + serverProperties.getContextPath());
    }
}
